package com.bzframework.example.mongo;

import com.bzframework.core.auth.Authorization;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author bingzhong
 * @Date 2025/8/25
 */
@Tag(name = "mongo数据库增删改查测试")
@RestController
@RequestMapping("/mongo")
@RequiredArgsConstructor
@Authorization(ignore = true)
public class MongoTestController {

    private final MongoTestRepository mongoTestRepository;

    @GetMapping("/find/all")
    @Operation(description = "获取所有mongo数据")
    public List<MongoTestEntity> findAll(){
        return mongoTestRepository.findAll();
    }

    @GetMapping("/find/{id}")
    @Operation(description = "获取一个mongo数据")
    public MongoTestEntity findOne(@PathVariable String id){
        return mongoTestRepository.findById(id).orElse(null);
    }

    @PostMapping("/add")
    @Operation(description = "添加mongo数据")
    public MongoTestEntity addOne(@RequestBody MongoTestEntity entity){
        return mongoTestRepository.save(entity);
    }

    @DeleteMapping("/remove/{id}")
    @Operation(description = "删除mongo数据")
    public void removeOne(@PathVariable String id){
        mongoTestRepository.deleteById(id);
    }

}
